package com.example.finaltool.model.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.finaltool.consts.Quhao;
import com.example.finaltool.consts.Table;
import com.example.finaltool.model.AreaInfo;
import com.example.finaltool.model.config.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * @author dengbw
 * @date 2021/8/18 2:58 下午
 */
@Getter
@Setter
@NoArgsConstructor
@TableName(Table.SYS_CORP)
public class SysCorp {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String name;
    private String dingCorpId;
    private String dingAgentId;
    private String dingAccessKey;
    private String dingAccessSecret;
    private String dingSsoSecret;
    private String dingSuiteTicket;
    private String remark;
    private Integer status;
    private Boolean isDel;
    private Long createUserId;
    private Timestamp createTime;
    private Long modifyUserId;
    private Timestamp modifyTime;
    private String tenantId;
    private Boolean needSync;
    private Integer provinceId;
    private Integer cityId;
    private Integer districtId;
    private Integer villageId;
    private Long subTenantId;
    private String areaCode;
    private Integer onlyTown;
    private String district;
    private String town;
    private String nickName;

    public static SysCorp newZhen(String name, Data data, AreaInfo info) {
        SysCorp corp = new SysCorp();
        corp.name = name;
        corp.dingCorpId = data.getCorpId();
        corp.dingAgentId = data.getAgentId();
        corp.dingAccessKey = data.getAppKey();
        corp.dingAccessSecret = data.getAppSecret();
        corp.dingSsoSecret = data.getSsosecret();
        corp.remark = name;
        corp.status = 1;
        corp.isDel = false;
        corp.tenantId = data.getCorpId();
        corp.needSync = false;
        corp.createTime = Timestamp.valueOf(LocalDateTime.now());
        corp.provinceId = 1;
        corp.cityId = info.getShiId().intValue();
        corp.districtId = info.getQuId().intValue();
        corp.areaCode = Quhao.get(data.getShi());
        corp.district = info.getQu();
        corp.town = info.getZhen();
        corp.nickName = data.getZhen();
        return corp;
    }
}
